//
//  dataViewController.m
//  dong
//
//  Created by dongchuang on 15/8/14.
//  Copyright (c) 2015年 mohekeji. All rights reserved.
//

#import "dataViewController.h"
#import "cellTableViewCell.h"
#define  header  65
#define id  zhangsan
@interface dataViewController ()

@end

@implementation dataViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _dd = @[
            @{
                @"header": @"我是头",
                @"footer": @"我是尾",
                @"list": @[
                        @{
                            @"title": @"张三"
                            
                            },@{
                            @"title": @"张三"
                            
                            }
                        ]
                },
            @{
                @"header": @"我是头",
                @"footer": @"我是尾",
                @"list": @[
                        @{
                            @"title": @"张三1"
                            
                            },@{
                            @"title": @"张三"
                            
                            }
                        ]
                },
            @{
                @"header": @"我是头",
                @"footer": @"我是尾",
                @"list": @[
                        @{
                            @"title": @"张三2"
                            
                            },@{
                            @"title": @"张三"
                            
                            }
                        ]
                }
            ];
  
    
[[NSUserDefaults standardUserDefaults] setValue:@"zhangsan" forKey:@"name"];
NSString *name =[[NSUserDefaults standardUserDefaults] valueForKey:@"name"];
[[NSUserDefaults standardUserDefaults]removeObjectForKey:@"name"];
    
    // Do any additional setup after loading the view from its nib.
}



-(void)sanmu
{
    int a,b;
    a=1;
    b=2;
    a<b?NSLog(@"%d",a):NSLog(@"%d",b);
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    ddViewController *nv = [[ddViewController alloc] init];
    [self.navigationController pushViewController:nv animated:YES];
    UIAlertView *akert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"确定要进入吗？" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    [akert show];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return _dd.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSDictionary *dic = [_dd objectAtIndex:section];
    NSArray *arr = [dic objectForKey:@"list"];
    return arr.count;
}

- (cellTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
      NSString *indentifier = @"cellTableViewCell";
    cellTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:indentifier];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"cellTableViewCell" owner:self options:nil] lastObject];
    }
    NSDictionary *dd = [_dd objectAtIndex:indexPath.section];
    NSArray *cc = dd[@"list"];
    NSDictionary *dc = [cc objectAtIndex:indexPath.row];
    cell.ddLabel.text = dc[@"title"];
    cell.deLabel.text =dc[@"content"];
    
    
    return cell;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return header;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] init];
    view.frame = CGRectMake(0, 0, 320, 59);
    view.backgroundColor = [UIColor yellowColor];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, 200, 21)];
    NSDictionary *dd =[_dd objectAtIndex:section];
    label.text = dd[@"header"];
    [view addSubview:label];
    return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return header;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] init];
    view.frame = CGRectMake(0, 0, 320, 0);
    view.backgroundColor = [UIColor yellowColor];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, 200, 21)];
    NSDictionary *dd =[_dd objectAtIndex:section];
    label.text = dd[@"footer"];
    [view addSubview:label];
    return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return header;
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    NSLog(@"页面将要出现");
}

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    NSLog(@"页面已经出现");
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    NSLog(@"页面将要消失");
    
}

-(void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    NSLog(@"页面已经消失");
}

@end
